#ifndef _bbox_h
#define _bbox_h


/**
  * \page bbox Bounding Box
  *
  * Bounding boxes are used for sprites and tiles to test collisions.
  * They are defined with top, bottom, left and right side location.
  * The size of a bounding box may be negative (e.g. when right of lower
  * then left). That kind of box is returned on collision test if there is
  * no intersection.
  *
  * \section define_bbox Defining a bbox
  * The bbox is a class. So you can get a new %bbox calling its default
  * empty constructor without any parameters. In this case the box has no
  * size.
  *
  * Usually you specify the position and size:
  * <tt>new bbox(left, top, right, bottom);</tt>
  *
  * \section bbox_comparison Compare BBoxes
  * You can compare a %bbox with other %BBoxes or integer numbers.
  * When comparing to numbers, it is always compared with the box' area,
  * which is calculated by multiplying its width and height.
  * If either width or height or both is negative, the area is always
  * returned as negative.
  *
  * \section bbox_intersection Test Intersection
  * For collision test you have to test intersection between two BBoxes.
  *
  * \code
  * bbox c = bbox::intersection(a, b);
  * \endcode
  *
  * If the intersection box' area is negative or equal to 0, there is no
  * collision.
  *
  * \code
  * if(c<0) printf("No collision!\n");
  * \endcode
  *
  * \image html intersection_1.png "Intersection" height=100px
  *
  * \image html intersection_2.png "No Intersection" height=100px
  */

/**
  * \brief Class for bounding boxes.
  *
  * Used for sprite and tile collision tests.
  */
class bbox
{
  private:
  int mLeft, mTop, mRight, mBottom;

  public:
  /**
    * \brief Empty bbox (all values are 0).
    */
  bbox();

  /**
    * \brief bbox constructor.
    */
  bbox(int left, int top, int right, int bottom);

  /**
    * \brief Get intersection bbox.
    *
    * If bboxes don't intersect, returned width or height is <= 0.
    *
    * \param a First bbox.
    * \param b Second bbox.
    * \return Intersection bbox.
    */
  static bbox intersection(bbox a, bbox b);
  
  /**
    * \brief Check whether point is inside the bbox.
    *
    * \param pos The position of the point
    * \return true if inside, otherwise false
    */
  bool inside(v2<int> pos);

  int left() const;
  int top() const;
  int right() const;
  int bottom() const;

  /**
    * \brief Get bbox width. May be negative.
    */
  int width() const;

  /**
    * \brief Get bbox height. May be negative.
    */
  int height() const;

  /**
    * \brief Get area (width*height).
    *
    * \return Area value in pixels. May be negative if width, height or both is negative.
    */
  int area() const;

  /**
    * \brief Move bbox relatively to current location.
    */
  void move(int dx, int dy);

  bool operator<(bbox a);
  bool operator<(int a);
  bool operator<=(bbox a);
  bool operator<=(int a);
  bool operator>(bbox a);
  bool operator>(int a);
  bool operator>=(bbox a);
  bool operator>=(int a);
  bool operator!=(bbox a);
  bool operator!=(int a);
  bool operator==(bbox a);
  bool operator==(int a);
};


#endif // #ifndef _bbox_h
